import Cookie from 'js-cookie' // 引入js-cookie库


const tokenKey = 'WKBTOKEN' // 定义token的key

export const getToken = () => {
    return Cookie.get(tokenKey) // 获取token
}
export const setToken = (token:string,tokenType:string) =>{
    const _token = {
        token,
        tokenType
    }
    localStorage.setItem("_token",JSON.stringify(_token))//将token存储到localStorage中

    return Cookie.set(tokenKey, token) // 设置token
}
export const removeToken = () =>{
    localStorage.removeItem('_token')
    return Cookie.remove(tokenKey) // 删除token
}

//设置 ID 相关

const projectIdKey = 'WKBPID' // 定义projectId的key

export const getProjectId = () => {
    return Cookie.get(projectIdKey) // 获取projectId  项目的id
}

export const setProjectId = (projectId:string) =>{
    // 使用Cookie.set方法设置projectId
    return Cookie.set(projectIdKey, projectId) // 设置projectId
}

export const removeProjectId = () =>{
    return Cookie.remove(projectIdKey) // 删除projectId
}

export const removeCookie = () =>{
    removeProjectId() // 删除projectId
    removeToken()   // 删除token 
}